#include "picturewidget.h"

PictureWidget::PictureWidget(QWidget *parent) : QWidget(parent)
{
    this->initUI();
    this->resize(600,700);
}

void PictureWidget::initUI()
{
    this->title=new QLabel("现场图片查看界面");
    this->ret_button=new QPushButton("返回");
    this->date_title=new QLabel("请输入日期");
    this->date_button=new QPushButton("日期控件");
    this->listWidget=new QListWidget();
    this->load_button=new QPushButton("加载更多");


    this->layout_H1=new QHBoxLayout();
    this->layout_H2=new QHBoxLayout();
    this->layout_H3=new QHBoxLayout();
    this->layout_H4=new QHBoxLayout();
    this->layout_H5=new QHBoxLayout();
    this->layout_V=new QVBoxLayout();

    this->layout_H1->addWidget(title);
    this->layout_H2->addWidget(ret_button);
    this->layout_H3->addWidget(date_title);
    this->layout_H3->addWidget(date_button);
    layout_H3->setSpacing(20);

    this->layout_H4->addWidget(listWidget);
    this->layout_H5->addWidget(load_button);

    this->layout_V->addLayout(layout_H1);
    this->layout_V->addLayout(layout_H2);
    this->layout_V->addLayout(layout_H3);
    this->layout_V->addLayout(layout_H4);
    this->layout_V->addLayout(layout_H5);



    date_button->setMinimumSize(150, 40); // 日期按钮尺寸
    listWidget->setMinimumHeight(400);    // 列表最小高度
    //layout_H1->addWidget(title);
    layout_H1->setAlignment(Qt::AlignCenter);//居中


    calendarWidget = new QCalendarWidget(this);
    calendarWidget->setWindowFlags(Qt::Popup); // 设置为弹出窗口



    listWidget->setStyleSheet("QListWidget {"
                                 "    border: none;"
                                 "}"
                                 "QScrollBar:vertical {"
                                 "    background: #f0f0f0;"
                                 "    width: 10px;"
                                 "}"
                                 "QScrollBar::handle:vertical {"
                                 "    background: #a0a0a0;"
                                 "    min-height: 20px;"
                                 "}"
                                 "QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {"
                                 "    height: 0px;"
                                 "}"
                                 "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {"
                                 "    background: none;"
                                 "}");
    //listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);//显示滑块
    connect(this->date_button,&QPushButton::clicked,this,&PictureWidget::showCalender);
    connect(calendarWidget, &QCalendarWidget::activated, this, &PictureWidget::selectCalender);

    this->setLayout(layout_V);



}


void PictureWidget::showCalender()
{
    QPoint pos=date_button->mapToGlobal(QPoint(0,date_button->height()));
    this->calendarWidget->move(pos);
    this->calendarWidget->show();
}

void PictureWidget::selectCalender(const QDate &date)
{
    QString dateStr = date.toString("yyyy-MM-dd");
    date_button->setText(dateStr);
    this->calendarWidget->hide();
}

